﻿
Option Compare Binary
Option Infer On
Option Strict On
Option Explicit On

Imports ATS.DBModel
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations
Imports System.Data
Imports System.Data.Objects
Imports System.Linq
Imports System.ServiceModel.DomainServices.EntityFramework
Imports System.ServiceModel.DomainServices.Hosting
Imports System.ServiceModel.DomainServices.Server


'Implements application logic using the atsEntities context.
' TODO: Add your application logic to these methods or in additional methods.
' TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
' Also consider adding roles to restrict access as appropriate.
'<RequiresAuthentication> _
'TODO: add the EnableClientAccessAttribute to this class to expose this DomainService to clients.
Public Class DomainService1
    Inherits LinqToEntitiesDomainService(Of atsEntities)
    
    'TODO:
    ' Consider constraining the results of your query method.  If you need additional input you can
    ' add parameters to this method or create additional query methods with different names.
    'To support paging you will need to add ordering to the 'MainAssetsTables' query.
    <Query(IsDefault:=True)> _
    Public Function GetMainAssetsTables() As IQueryable(Of MainAssetsTable)
        Return Me.ObjectContext.MainAssetsTables
    End Function
    
    Public Sub InsertMainAssetsTable(ByVal mainAssetsTable As MainAssetsTable)
        If ((Me.GetEntityState(mainAssetsTable) = EntityState.Detached)  _
                    = false) Then
            Me.ObjectContext.ObjectStateManager.ChangeObjectState(mainAssetsTable, EntityState.Added)
        Else
            Me.ObjectContext.MainAssetsTables.AddObject(mainAssetsTable)
        End If
    End Sub
    
    Public Sub UpdateMainAssetsTable(ByVal currentMainAssetsTable As MainAssetsTable)
        Me.ObjectContext.MainAssetsTables.AttachAsModified(currentMainAssetsTable, Me.ChangeSet.GetOriginal(currentMainAssetsTable))
    End Sub
    
    Public Sub DeleteMainAssetsTable(ByVal mainAssetsTable As MainAssetsTable)
        If ((Me.GetEntityState(mainAssetsTable) = EntityState.Detached)  _
                    = false) Then
            Me.ObjectContext.ObjectStateManager.ChangeObjectState(mainAssetsTable, EntityState.Deleted)
        Else
            Me.ObjectContext.MainAssetsTables.Attach(mainAssetsTable)
            Me.ObjectContext.MainAssetsTables.DeleteObject(mainAssetsTable)
        End If
    End Sub
    
        
        Private Function GetEntityState(ByVal entity As Object) As EntityState
            Dim stateEntry As ObjectStateEntry = Nothing
            If (Me.ObjectContext.ObjectStateManager.TryGetObjectStateEntry(entity, stateEntry) = false) Then
                Return EntityState.Detached
            End If
            Return stateEntry.State
        End Function

End Class

